$(document).ready(function() {
    var dO = new Date();
    var d = dO.getDate();
    var m = dO.getMonth();
    var y = dO.getFullYear();
    var today = y + "-" + m + "-" + d;
    $('#issueDate').DatePicker({
        format:'Y-m-d',
        date:dO,
        current: dO,
        starts: 1,
        position: 'right',
        onBeforeShow: function() {
            $('#issueDate').DatePickerSetDate(dO, true);
        },
        onChange: function(formated, dates) {
            $('#issueDate').val(formated);
            isDateFormated(document.getElementById('issueDate').value);
        }
    });

    $('#startedDate').DatePicker({
        format:'Y-m-d',
        date:dO,
        current: dO,
        starts: 1,
        position: 'right',
        onBeforeShow: function() {
            $('#startedDate').DatePickerSetDate(dO, true);
        },
        onChange: function(formated, dates) {
            $('#startedDate').val(formated);
            isDateFormated(document.getElementById('startedDate').value);
        }
    });

    $('#endingDate').DatePicker({
        format:'Y-m-d',
        date:dO,
        current: dO,
        starts: 1,
        position: 'right',
        onBeforeShow: function() {
            $('#endingDate').DatePickerSetDate(dO, true);
        },
        onChange: function(formated, dates) {
            $('#endingDate').val(formated);
            //isDateFormated(document.getElementById('endingDate').value);
        }
    });

    $('#dateOfBirth').DatePicker({
        format:'Y-m-d',
        date:dO,
        current: dO,
        starts: 1,
        position: 'right',
        onBeforeShow: function() {
            $('#dateOfBirth').DatePickerSetDate(dO, true);
        },
        onChange: function(formated, dates) {
            $('#dateOfBirth').val(formated);
            isDateFormated(document.getElementById('dateOfBirth').value);
        }
    });


    $('#submitDate').DatePicker({
        format:'Y-m-d',
        date:dO,
        current: dO,
        starts: 1,
        position: 'right',
        onBeforeShow: function() {
            $('#submitDate').DatePickerSetDate(dO, true);
        },
        onChange: function(formated, dates) {
            $('#submitDate').val(formated);
            isDateFormated(document.getElementById('submitDate').value);
        }
    });

    $('#planDate').DatePicker({
        format:'Y-m-d',
        date:dO,
        current: dO,
        starts: 1,
        position: 'right',
        onBeforeShow: function() {
            $('#planDate').DatePickerSetDate(dO, true);
        },
        onChange: function(formated, dates) {
            $('#planDate').val(formated);
            isDateFormated(document.getElementById('planDate').value);
        }
    });
});

function selectDate(id) {
    var dO = new Date();
    var d = dO.getDate();
    var m = dO.getMonth();
    var y = dO.getFullYear();
    var today = y + "-" + m + "-" + d;
    $('#' + id).DatePicker({
        format:'Y-m-d',
        date:dO,
        current: dO,
        starts: 1,
        position: 'right',
        onBeforeShow: function() {
            $('#' + id).DatePickerSetDate(dO, true);
        },
        onChange: function(formated, dates) {
            $('#' + id).val(formated);
            //isDateFormated($('#'+id).val());
        }
    });
    try {
        isDateFormated($('#'+id).val());
    }catch(err) {
        console.log(err.toString());
    }
}